/**
 * js配置文件
 */
const HTTP = "http://192.168.178.46:80/"
// const HTTP = "http://localhost:8080/"

axios.interceptors.request.use(function(config) {
	// alert(9);
	config.headers['jwttoken'] = localStorage.getItem('jwtToken')
	return config;
}, function(error) {
	return Promise.reject(error);
});

//格式化时间
function datetimeFormat(data) {
	let dtime = new Date(data)
	const year = dtime.getFullYear()
	let month = dtime.getMonth() + 1
	if (month < 10) {
		month = '0' + month
	}
	let day = dtime.getDate()
	if (day < 10) {
		day = '0' + day
	}
	let hour = dtime.getHours()
	if (hour < 10) {
		hour = '0' + hour
	}
	let minute = dtime.getMinutes()
	if (minute < 10) {
		minute = '0' + minute
	}
	let second = dtime.getSeconds()
	if (second < 10) {
		second = '0' + second
	}
	return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
}

//把json数组对象转换位数格式的json
function arrayToTree(items) {
	const rootItems = [];
	const lookup = {};

	for (const item of items) {
		const itemId = item.id; //取对象的唯一id
		lookup[itemId] = item;
		const parentId = item.parentid; //父id的属性
		if (parentId === null || parentId === "0" || parentId === 0) {
			rootItems.push(item);
		} else {
			const parent = lookup[parentId];
			if (parent) {
				if (!parent.children) {
					parent.children = [];
				}
				parent.children.push(item);
			}
		}
	}

	return rootItems;
}



//把json数组对象转换位数格式的json
function arrayToTree2(items) {
	const rootItems = [];
	const lookup = {};

	for (const item of items) {
		const itemId = item.aid; //取对象的唯一id
		lookup[itemId] = item;
		const parentId = item.parentid; //父id的属性
		if (parentId === null || parentId === "0" || parentId === 0) {
			rootItems.push(item);
		} else {
			const parent = lookup[parentId];
			if (parent) {
				if (!parent.children) {
					parent.children = [];
				}
				parent.children.push(item);
			}
		}
	}

	return rootItems;
}

function arrayToTree3(items) {
	const rootItems = [];
	const lookup = {};

	for (const item of items) {
		const itemId = item.id; //取对象的唯一id
		lookup[itemId] = item;
		const parentId = item.materialfaid; //父id的属性
		if (parentId === null || parentId === "0" || parentId === 0) {
			rootItems.push(item);
		} else {
			const parent = lookup[parentId];
			if (parent) {
				if (!parent.children) {
					parent.children = [];
				}
				parent.children.push(item);
			}
		}
	}
	return rootItems;
}